package 反射;

import org.junit.Test;

import java.util.stream.Stream;

/**
 * @功能
 * @创建时间 2020/5/6
 */
public class MyTest2 {
    @Test
    public void test(){
    UserController userController = new UserController();
    Class<? extends UserController> clazz = userController.getClass();
    UserService userService = new UserService();
    //获取所有的属性值
    Stream.of(clazz.getDeclaredFields()).forEach(field -> {
        String name = field.getName();
        AutWare annotation = field.getAnnotation(AutWare.class);
        if(annotation!=null){
            field.setAccessible(true);
            //获取属性的类型
            Class<?> type = field.getType();
            try {
                Object o = type.newInstance();
                field.set(userController,o);
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    });

}
    }